package com.huike.web.controller.clues;

import com.huike.clues.domain.TbCourse;
import com.huike.clues.domain.dto.TbCourseDTO;
import com.huike.clues.service.TbCourseService;
import com.huike.common.annotation.Log;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程管理Controller
 *
 * @date 2023-04-01
 */

@RestController
@RequestMapping("/clues/course")
public class TbCourseController extends BaseController {


    @Autowired
    private TbCourseService tbCourseService;
    /**
     * 分页查询课程列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbCourseDTO tbCourseDTO) {
        startPage();
        List<TbCourse> list = tbCourseService.listTbCourse(tbCourseDTO);
        return getDataTable(list);
    }
    /**
     * 新增课程
     *
     * @param tbCourse
     */
    @Log(title = "课程管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCourse tbCourse) {
        tbCourseService.add(tbCourse);
        return AjaxResult.success();
    }
    /**
     * 课程信息回显
     *
     * @param id
     */
    @GetMapping("/{id}")
    public AjaxResult findById(@PathVariable Long id) {
        return AjaxResult.success(tbCourseService.findById(id));
    }
    /**
     * 修改课程
     *
     * @param tbCourse
     */
    @PutMapping
    public AjaxResult updateById(@RequestBody TbCourse tbCourse) {
        tbCourseService.updateTbCourse(tbCourse);
        return AjaxResult.success();
    }

    /**
     * 批量删除
     *
     * @param ids
     */
    @DeleteMapping("/{ids}")
    public AjaxResult deleteByIds(@PathVariable Long[] ids) {
        tbCourseService.deleteByIds(ids);
        return AjaxResult.success();
    }
}
